{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6, 9, 6, 1, 1, 2, 8, 7, 3, 5, 6, 3, 5, 3, 5, 8, 8, 2, 8, 1, 7, 8,\n",
       "       7, 2, 1, 2, 9, 9, 4, 9])"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.seed(1)\n",
    "X = np.random.randint(1, 10, size=30)\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6, 9, 6],\n",
       "       [1, 1, 2],\n",
       "       [8, 7, 3],\n",
       "       [5, 6, 3],\n",
       "       [5, 3, 5],\n",
       "       [8, 8, 2],\n",
       "       [8, 1, 7],\n",
       "       [8, 7, 2],\n",
       "       [1, 2, 9],\n",
       "       [9, 4, 9]])"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = X.reshape(-1,3)\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6, 9, 1],\n",
       "       [1, 1, 0],\n",
       "       [8, 7, 0],\n",
       "       [5, 6, 0],\n",
       "       [5, 3, 1],\n",
       "       [8, 8, 0],\n",
       "       [8, 1, 2],\n",
       "       [8, 7, 0],\n",
       "       [1, 2, 2],\n",
       "       [9, 4, 2]])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = A[:,2:3]\n",
    "a[np.argwhere(a <= 3)[:,0]] = 0\n",
    "a[np.argwhere((a > 3) & (a <= 6))[:,0]] = 1\n",
    "a[np.argwhere(a > 6)[:,0]] = 2\n",
    "A\n",
    "#print(a[np.argwhere(a <= 3)[0]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "样本0:\n",
      "[[1 1]\n",
      " [8 7]\n",
      " [5 6]\n",
      " [8 8]\n",
      " [8 7]]\n",
      "样本1:\n",
      "[[6 9]\n",
      " [5 3]]\n",
      "样本2:\n",
      "[[8 1]\n",
      " [1 2]\n",
      " [9 4]]\n"
     ]
    }
   ],
   "source": [
    "b = A[:,2:3]\n",
    "ind = np.argwhere(b == 0)[:,0]\n",
    "B0 = A[ind,0:2]\n",
    "ind = np.argwhere(b == 1)[:,0]\n",
    "B1 = A[ind,0:2]\n",
    "ind = np.argwhere(b == 2)[:,0]\n",
    "B2 = A[ind,0:2]\n",
    "print('样本0:\\n{}'.format(B0))\n",
    "print('样本1:\\n{}'.format(B1))\n",
    "print('样本2:\\n{}'.format(B2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
